<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="../../../static/css/font.css">
        <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
        <link rel="stylesheet" href="../../../static/css/xadmin.css">
        <script type="text/javascript" src="../../../static/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="../../../static/js/xadmin.js"></script>
        <script src="../../../static/js/axios.min.js" charset="utf-8"></script>
        <script src="../../../js/api/agency.js" charset="utf-8"></script>
        <script src="../../../js/api/group.js" charset="utf-8"></script>
        <script src="../../../js/api/user.js" charset="utf-8"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <div class="layui-card">
                        <div class="layui-card-header">基本信息</div>
                        <div class="layui-card-body">
                            <div class="layui-form-item">
                                <label for="name" class="layui-form-label">
                                    <span class="x-red">*</span>用户姓名
                                </label>
                                <div class="layui-input-inline">
                                    <input type="text" id="name" name="name" required="" lay-verify="required"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="tel" class="layui-form-label">
                                    <span class="x-red">*</span>联系电话
                                </label>
                                <div class="layui-input-inline">
                                    <input type="text" id="tel" name="tel" required="" lay-verify="required"
                                           autocomplete="off" class="layui-input">
                                </div>
                                <label for="email" class="layui-form-label">
                                    邮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;箱
                                </label>
                                <div class="layui-input-inline">
                                    <input type="email" id="email" name="email"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="remark" class="layui-form-label">
                                    备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注
                                </label>
                                <div class="layui-input-block">
                                    <textarea placeholder="请输入内容" class="layui-textarea" id="remark" name="remark"></textarea>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-card">
                        <div class="layui-card-header">账户信息</div>
                        <div class="layui-card-body">
                            <div class="layui-form-item">
                                <label for="utype" class="layui-form-label">
                                    账户类型
                                </label>
                                <div class="layui-input-inline">
                                    <select id="utype">
                                        <option value="">后台管理账户</option>
                                        <option value="1">接口使用账户</option>
                                        <option value="2">综合账户</option>
                                    </select>
                                </div>
                                <label for="agency" class="layui-form-label">
                                    所属机构
                                </label>
                                <div class="layui-inline layui-show-xs-block" id="agency">
                                </div>

                            </div>
                            <div class="layui-form-item">
                                <label for="uname" class="layui-form-label">
                                    <span class="x-red">*</span>账&nbsp;&nbsp;户&nbsp;&nbsp;号
                                </label>
                                <div class="layui-input-inline">
                                    <input type="text" id="uname" name="uname" required="" lay-verify="required"
                                           autocomplete="off" class="layui-input">
                                </div>
                                <label for="email" class="layui-form-label">
                                    <span class="x-red">*</span>密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码
                                </label>
                                <div class="layui-input-inline">
                                    <input type="text" id="password" name="password" required="" lay-verify="required"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <button  class="layui-btn" lay-filter="add" lay-submit="">
                            保存
                        </button>
                    </div>
                </form>
            </div>
        </div>
        <script>
            layui.config({
                base: './../../../static/lib/dist/'
            })

            layui.use(['form', 'layer', 'selectPlus', 'notice'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                selectPlus = layui.selectPlus,
                notice = layui.notice,
                layer = layui.layer;

                var agencyinfo = null

                getChildAgencys().then(value => {
                    if(value.code == 200){
                        agencyinfo = selectPlus.render({
                            el: '#agency',
                            data: value.data,
                            type: "radio",
                            valueName: "agencyCode",
                            label: ["agencyName"],
                            values: layui.data('user').info.agencyCode
                        });
                    }else{
                        notice.error('查询用户机构信息失败')
                    }
                })


                //监听提交
                form.on('submit(add)',
                function(data) {
                    var obj = agencyinfo.getChecked();
                    let params = data.field
                    params.agencyCode = obj.values[0]
                    delete params.selectPlusradio1;
                    saveUser(params).then(value => {
                        if(value.code == 200){
                            layer.alert("保存成功", {
                                    icon: 6
                                },
                                function() {
                                    //关闭当前frame
                                    xadmin.close();

                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                        }else{
                            notice.error('保存失败，'+value.msg)
                        }
                    }).catch(reason => {
                        notice.error('服务器未连接')
                    })
                    return false;
                });

            });</script>
        <script>var _hmt = _hmt || []; (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();</script>
    </body>

</html>
